home *** CD-ROM | disk | FTP | other *** search
/ Trading on the Edge / Trading On The Edge - CD-ROM Toolkit (Wayzata Technology)(2031)(1994).bin / pc / shared / snns / snnsv3_0.z / snnsv3_0 / SNNSv3.0 / tools / sources / feedback-gennet.c < prev    next >
C/C++ Source or Header  |  1993-03-25  |  6KB  |  156 lines

  1. /******************************************************************************/
  2. /*     FILE    :  feedback-gennet.c                                           */
  3. /*     TYPE    :  program module                                              */
  4. /*     AUTHORS :  Martin Reczko                                               */
  5. /*     DATE    :  1.3.93                                                      */
  6. /*     VERSION :  1.0                                                         */
  7. /******************************************************************************/
  8. /*
  9.   Generate a SNNS network file for fully recurrent networks.
  10.   The network has the following structure:
  11.     - input layer with no intra layer connections
  12.     - fully recurrent hidden layer
  13.     - output layer: connections from each hidden unit to each output unit AND
  14.      OPTIONALLY fully recurrent intra layer connections in the output layer AND
  15.      OPTIONALLY feedback connections from each output unit to each hidden unit
  16.   The activation function of the output units can be set to
  17.   sigmoidal or linear. All weights are initialized with 0.0 .
  18.   Other initializations should be performed by the init functions in SNNS.
  19. */
  20. #include <ctype.h>
  21. #include <stdio.h>
  22. #include <string.h>
  23. #include <stdlib.h>
  24.  
  25. FILE *in,*out;
  26. float amplitude;
  27.  
  28. double drand48()
  29. {
  30.  return 0.0;
  31. }
  32.  
  33. void main ()
  34. {
  35.  int i,j,k;
  36.  int nin,nhid,nout,nconnections;
  37.  char netname[1024];
  38.  char in2out,out2out,linout,out2hid;
  39.  int last_output_source;
  40.  
  41.  printf("Enter # input units:");
  42.  scanf("%d",&nin);
  43.  printf("Enter # hidden units:");
  44.  scanf("%d",&nhid);
  45.  printf("Enter # output units:");
  46.  scanf("%d",&nout);
  47.  printf("INTRA layer connections in the output layer (y/n):");
  48.  scanf("\n%c",&out2out);
  49.  printf("feedback connections from output to hidden units (y/n):"),
  50.  scanf("\n%c",&out2hid);
  51.  printf("Linear output activation function (y/n):");
  52.  scanf("\n%c",&linout);
  53.  printf("Enter name of network file:");
  54.  scanf("\n%s",netname);
  55.  
  56.  printf("working...");
  57.  if (out2out=='y') {
  58.    last_output_source=nout;
  59.    if (out2hid=='y')
  60.      nconnections = nhid *(nin+nhid+nout);
  61.    else
  62.      nconnections = nhid *(nin+nhid);
  63.     nconnections += nout *(nhid+nout);
  64.  } else {
  65.    last_output_source=0;
  66.    if (out2hid=='y')
  67.      nconnections = nhid *(nin+nhid+nout);
  68.    else
  69.      nconnections = nhid *(nin+nhid);
  70.    nconnections += nout * nhid;
  71.  }
  72.  if ((out = fopen(netname, "w")) ==  NULL)
  73.    {  
  74.      fprintf (stderr, "error:  can't create file %s\n", netname) ;
  75.      exit(0);
  76.    } 
  77.  
  78.  fprintf(out,"SNNS network definition file V1.4-3D\n");
  79.  fprintf(out,"generated at Sat Jan 23 16:55:30 1992\n");
  80.  fprintf(out,"\n");
  81.  fprintf(out,"network name : rec-gennet\n");
  82.  fprintf(out,"source files :\n");
  83.  fprintf(out,"no. of units : %d\n",nin+nhid+nout);
  84.  fprintf(out,"no. of connections : %d\n",nconnections);
  85.  fprintf(out,"no. of unit types : 0\n");
  86.  fprintf(out,"no. of site types : 0\n");
  87.  fprintf(out,"\n");
  88.  fprintf(out,"learning function : QPTT\n");
  89.  fprintf(out,"update function   : BPTT_Order\n");
  90.  fprintf(out,"\n");
  91.  fprintf(out,"unit default section :\n");
  92.  fprintf(out,"\n");
  93.  fprintf(out,"---------|----------|----|--------|-------|--------------|-------------\n");
  94.  fprintf(out," 0.00000 |  0.00000 | h  |      0 |     1 | Act_Logistic | Out_Identity \n");
  95.  fprintf(out,"---------|----------|----|--------|-------|--------------|-------------\n");
  96.  fprintf(out,"\n");
  97.  fprintf(out,"unit definition section :\n");
  98.  fprintf(out,"\n");
  99.  fprintf(out,"----|----------|----------|----------|----------|----|----------|--------------|--------------|-------\n");
  100.  
  101.  for (i=1;i<=nin;i++) fprintf(out,
  102. "%4d|          |          |  0.00000 |  0.00000 | i  | %2d, 1, 2 |              |              | \n",i,i);
  103.  for (i=1;i<=nhid;i++) fprintf(out,
  104. "%4d|          |          |  0.00000 |  0.00000 | h  | %2d, 2, 2 |              |              | \n",i+nin,i);
  105.  for (i=1;i<=nout;i++) if (linout=='y') fprintf(out,
  106. "%4d|          |          |  0.00000 |  0.00000 | o  | %2d, 3, 2 | Act_Identity |              | \n",i+nin+nhid,i); else fprintf(out,
  107. "%4d|          |          |  0.00000 |  0.00000 | o  | %2d, 3, 2 |              |              | \n",i+nin+nhid,i);
  108.  fprintf(out,
  109. "----|----------|----------|----------|----------|----|----------|--------------|--------------|-------\n\n");
  110.  fprintf(out,"connection definition section :\n\n");
  111.  fprintf(out,"target | site | source:weight\n");
  112.  fprintf(out,
  113. "-------|------|----------------------------------------------------------------------------------------------------------------\n");
  114.   if (out2hid=='y')
  115.   for (j=1;j<=nhid;j++){
  116.    for (i=1;i<=(nin+nhid+nout);i++) {
  117.      if (i==1)
  118.        fprintf(out,"  %4d |      |",j+nin);
  119.      else
  120.        if ( ( (i-1) % 8) == 0) fprintf(out,"\n               ");
  121.      fprintf(out," %3d:%8.5f",i,drand48());
  122.      if (i < (nin+nhid+nout)) fprintf(out,",");
  123.    }
  124.    fprintf(out,"\n");
  125.  }
  126.  else
  127.  for (j=1;j<=nhid;j++){
  128.    for (i=1;i<=(nin+nhid);i++) {
  129.      if (i==1)
  130.        fprintf(out,"  %4d |      |",j+nin);
  131.      else
  132.        if ( ( (i-1) % 8) == 0) fprintf(out,"\n               ");
  133.      fprintf(out," %3d:%8.5f",i,drand48());
  134.      if (i < (nin+nhid)) fprintf(out,",");
  135.    }
  136.    fprintf(out,"\n");
  137.  }
  138.  
  139.  for (j=1;j<=nout;j++){
  140.    for (i=1;i<=(nhid+last_output_source);i++) {
  141.      if (i==1)
  142.        fprintf(out,"  %4d |      |",j+nin+nhid);
  143.      else
  144.        if ( ( (i-1) % 8) == 0) fprintf(out,"\n               ");
  145.      fprintf(out," %3d:%8.5f",i+nin,drand48());
  146.      if (i < (nhid+last_output_source)) fprintf(out,",");
  147.    }
  148.    fprintf(out,"\n");
  149.  }
  150.  fprintf(out,
  151. "-------|------|----------------------------------------------------------------------------------------------------------------\n");
  152.  fclose(out);
  153.  printf("\ngenerated %s\n",netname);
  154. }
  155.  
  156.